package demo603;

import java.sql.SQLException;
import java.util.Scanner;

public class ViewMain {

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        System.out.println("欢迎来到用户管理系统");
        System.out.println("请选择对应的操作");
        System.out.println("1. 登录");
        System.out.println("2. 注册");

        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();

        UserDao userDao = new UserDao(); // 提前初始化

        switch (i) {
            case 1:
                // 实现的是登录功能：只需要调用登录功能即可
                System.out.println("请输入用户名：");
                String username = scanner.next();
                System.out.println("请输入密码：");
                String password = scanner.next();

                User user = userDao.findUser(username, password);

                if (user != null) {
                    System.out.println("登录成功");
                } else {
                    System.out.println("登录失败");
                }
                break;
            case 2:
                // 实现注册功能
                System.out.println("请输入注册用户名：");
                String registerUsername = scanner.next();
                System.out.println("请输入注册密码：");
                String registerPassword = scanner.next();

                // 调用 UserDao 的注册方法（假设该方法名为 registerUser）
                boolean registerSuccess = userDao.register(registerUsername, registerPassword);


                if (registerSuccess) {
                    System.out.println("注册成功");
                } else {
                    System.out.println("注册失败");
                }
                break;
            default:
                System.out.println("无效的操作，请重新选择");
                break;
        }
    }
}
